home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
music
/
eked-m1.zoo
/
src
/
icon.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-02-19
|
25KB
|
919 lines
/*
* EKED-M1 : Editor for Korg M1 synth; icon.c : icon window
* Copyright (C) 1995 Steven M. Eker (Steven.Eker@brunel.ac.uk)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <gemfast.h>
#include <aesbind.h>
#include <vdibind.h>
#include "gm/gem_man.h"
#include "eked-m1.h"
#include "defs.h"
#include "types.h"
#include "externs.h"
#define N_ICONS 12
#define LAST_BANK 9
#define M1 10
#define CARD 11
typedef struct {
BOOL exists;
OBJECT *icon;
int x;
int y;
BANK *bank;
} ICON;
typedef struct {
enum {
NO_CHANGE,
COPY_FOUND,
COPY_NEEDED,
SAME_AS
} type;
int original;
int new;
} SLOT;
static OBJECT *dialog_enable;
static OBJECT *comb_copy;
static OBJECT *prog_copy;
static OBJECT *bank_copy;
static OBJECT *bank_tx;
static OBJECT *bank_rx;
static OBJECT *bank_print;
static OBJECT *bank_erase;
static OBJECT *bank_flip;
static OBJECT *ceff_copy;
static OBJECT *peff_copy;
static ICON icon_tab[N_ICONS];
static ICON *selected;
static ICON *dest;
static int work_w;
static int work_h;
static int icon_handle;
static int last_bank = -1;
static SLOT *track_programs(BYTE *comb, BYTE *dp, BYTE *sp);
static void display(int x_pos, int y_pos, GRECT *clip, long usr_val);
static int action(int handle, E_TYPE type, void *event,
int x_pos, int y_pos, long usr_val);
static ICON *find_icon(int x, int y);
static void update_icon(int handle, int x_pos, int y_pos, ICON *t);
void ic_init()
{
int x, y, n, gap_h, bank_w, bank_h;
OBJECT *icon_form;
rm_gaddr(R_TREE, ICON_FORM, &icon_form);
rm_gaddr(R_TREE, DIALOG_ENABLE, &dialog_enable);
rm_gaddr(R_TREE, COMB_COPY, &comb_copy);
rm_gaddr(R_TREE, PROG_COPY, &prog_copy);
rm_gaddr(R_TREE, BANK_COPY, &bank_copy);
rm_gaddr(R_TREE, BANK_TX, &bank_tx);
rm_gaddr(R_TREE, BANK_RX, &bank_rx);
rm_gaddr(R_TREE, BANK_PRINT, &bank_print);
rm_gaddr(R_TREE, BANK_ERASE, &bank_erase);
rm_gaddr(R_TREE, BANK_FLIP, &bank_flip);
rm_gaddr(R_TREE, CEFF_COPY, &ceff_copy);
rm_gaddr(R_TREE, PEFF_COPY, &peff_copy);
icon_tab[M1].icon = icon_form + M1_ICON;
icon_tab[CARD].icon = icon_form + CARD_ICON;
icon_form += BANK_ICON;
gap_h = char_h / 2;
bank_w = icon_form->ob_width + char_w;
bank_h = icon_form->ob_height + gap_h;
work_w = char_w + 5 * bank_w;
work_h = gap_h + 2 * bank_h + icon_tab[CARD].icon->ob_height + gap_h;
icon_tab[M1].exists = TRUE;
icon_tab[M1].x = char_w;
icon_tab[M1].y = gap_h + 2 * bank_h;
icon_tab[CARD].exists = TRUE;
icon_tab[CARD].x = char_w + icon_tab[M1].icon->ob_width + char_w;
icon_tab[CARD].y = gap_h + 2 * bank_h;
y = gap_h;
for(n = 0, x = char_w; n <= 4; n++, x += bank_w){
icon_tab[n].exists = FALSE;
icon_tab[n].icon = icon_form;
icon_tab[n].x = x;
icon_tab[n].y = y;
}
y += bank_h;
for(n = 5, x = char_w; n <= 9; n++, x += bank_w){
icon_tab[n].exists = FALSE;
icon_tab[n].icon = icon_form;
icon_tab[n].x = x;
icon_tab[n].y = y;
}
}
void ic_exit()
{
int i;
for(i = 0; i <= last_bank; i++)
FREE(icon_tab[i].bank);
}
void ic_window()
{
int t;
t = wm_open(NAME | CLOSER | FULLER | MOVER | SIZER |
UPARROW | DNARROW | VSLIDE | LFARROW | RTARROW | HSLIDE,
(GRECT *) 0, "EKED-M1", work_w, work_h, char_w, char_h,
&display, &action, 0L);
if(t < 0){
fm_alert(1, WINDOW_ALERT);
return;
}
icon_handle = t;
}
void ic_dialogs()
{
static struct {
int name;
OBJECT **objp;
} table[] = {
{DE_BANKCOPY, &bank_copy},
{DE_BANKERASE, &bank_erase},
{DE_BANKTX, &bank_tx},
{DE_BANKRX, &bank_rx},
{DE_BANKPRINT, &bank_print},
{DE_COMB, &comb_copy},
{DE_PROG, &prog_copy},
{DE_BANKFLIP, &bank_flip},
{DE_CEFF, &ceff_copy},
{DE_PEFF, &peff_copy}
};
int i;
for(i = 0; i < 10; i++){
if((*table[i].objp)->ob_state & DISABLED)
dialog_enable[table[i].name].ob_state &= ~SELECTED;
else
dialog_enable[table[i].name].ob_state |= SELECTED;
}
if(fm_dialog(dialog_enable, 0, NULL, 0) == DE_OK){
for(i = 0; i < 10; i++){
if(dialog_enable[table[i].name].ob_state & SELECTED)
(*table[i].objp)->ob_state &= ~DISABLED;
else
(*table[i].objp)->ob_state |= DISABLED;
}
}
}
void ic_newbank()
{
ICON *p;
BANK *bank;
int x_pos, y_pos;
long usr_val;
if(last_bank == LAST_BANK){
fm_alert(1, BANKMAX_ALERT);
return;
}
bank = MALLOC(BANK);
if(bank == NULL){
fm_alert(1, BANKMEM_ALERT);
return;
}
memset((char *) bank, 0, sizeof(BANK));
last_bank++;
p = icon_tab + last_bank;
p->bank = bank;
p->exists = TRUE;
bank->bank_nr = p - icon_tab;
bank->glob_win = bank->comb_win = bank->prog_win = 0;
bank->filename[0] = '\0';
wm_getdata(icon_handle, &x_pos, &y_pos, &usr_val);
update_icon(icon_handle, x_pos, y_pos, p);
}
void ic_bankop(int op)
{
BANK *bank;
int n;
if(!selected)
return;
bank = selected->bank;
if(bank == NULL)
return;
n = selected - icon_tab;
switch(op){
case M_GLOB_EDIT:
if(bank->glob_win != 0)
wm_topped(bank->glob_win);
else
ge_window(bank);
break;
case M_COMB_LIST:
if(bank->comb_win != 0)
wm_topped(bank->comb_win);
else
ls_window(COMB_LIST, bank);
break;
case M_PROG_LIST:
if(bank->prog_win != 0)
wm_topped(bank->prog_win);
else
ls_window(PROG_LIST, bank);
break;
case M_OPEN:
load_bank(bank);
break;
case M_SAVE_AS:
save_bank(bank, TRUE);
break;
case M_SAVE:
save_bank(bank, FALSE);
break;
case M_PRINT:
ic_bankprint(n);
break;
case M_COPY:
ic_bankcopy(n, n);
break;
case M_FLIP:
ic_bankflip(n);
break;
case M_ERASE:
ic_bankerase(n);
break;
case M_TRANSMIT:
ic_banktx(FALSE, n);
break;
case M_RECEIVE:
ic_bankrx(n, FALSE);
break;
}
}
void ic_combcopy(int db, int dc, int sb, int sc)
{
static int msg[] = {UPDATE_ITEM, 0};
BYTE *d, *s;
BOOL redraw_prog;
int t, i;
SLOT *link = NULL;
if(!(comb_copy->ob_state & DISABLED)){
unum1_update(comb_copy + CC_FROM_BANK, sb);
unum_update(comb_copy + CC_FROM_COMB, sc);
unum1_update(comb_copy + CC_TO_BANK, db);
unum_update(comb_copy + CC_TO_COMB, dc);
fm_begin_dialog(comb_copy, 0);
do{
t = fm_run_dialog();
switch(t){
case CC_FROM_BANK:
sb = fm_roll(comb_copy, t, sb, 0, last_bank, &unum1_update);
break;
case CC_FROM_COMB:
sc = fm_roll(comb_copy, t, sc, 0, 99, &unum_update);
break;
case CC_TO_BANK:
db = fm_roll(comb_copy, t, db, 0, last_bank, &unum1_update);
break;
case CC_TO_COMB:
dc = fm_roll(comb_copy, t, dc, 0, 99, &unum_update);
break;
}
}while(t != CC_OK && t != CC_CANCEL);
fm_end_dialog();
if(t == CC_CANCEL || (sb == db && sc == dc))
return;
}
d = COMB_DATA(icon_tab[db].bank, dc);
s = COMB_DATA(icon_tab[sb].bank, sc);
if((comb_copy[CC_REF].ob_state & SELECTED)
&& (comb_copy[CC_COMB].ob_state & SELECTED)
&& sb != db){
link = track_programs(s,
ic